package com.itheima.controller;

<<<<<<< HEAD
import javax.servlet.annotation.WebServlet;

@WebServlet("/orders/*")
public class OrdersServlet extends BaseServlet {

=======
import com.github.pagehelper.PageInfo;
import com.itheima.domain.Orders;
import com.itheima.util.BeanUtil;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

@WebServlet("/orders/*")
public class OrdersServlet extends BaseServlet {
    //查询所有订单信息
    private void findAll(HttpServletRequest req, HttpServletResponse resp) throws Exception {
        //获取前端传递的当前页码和显示的条数
        String pageNum = req.getParameter("pageNum");
        String pageSize = req.getParameter("pageSize");

        //调用findAll方法，获取orders集合
        List<Orders> list = ordersService.findAll(pageNum,pageSize);

        //将数据交由分页插件处理获取分页信息
        PageInfo<Orders> pageInfo = new PageInfo<Orders>(list);

        //存入作用域
        req.setAttribute("page",pageInfo);

        //页面跳转
        req.getRequestDispatcher("/pages/orders-list.jsp").forward(req,resp);
    }

    //批量删除订单信息
    private void deleteByIds(HttpServletRequest req, HttpServletResponse resp) throws Exception {
        //获取ids
        String ids = req.getParameter("ids");

        //调用批量删除订单信息方法
        boolean flag = ordersService.deleteByIds(ids);

        //判断flag的值，确定是否删除成功
        if(flag){
            //调用findAll方法
            findAll(req, resp);
        }else {
            //跳转到错误页面
            req.getRequestDispatcher("/pages/error.jsp").forward(req,resp);
        }
    }

    //根据Id查询当前题目信息并跳转到修改页面
    private void findById(HttpServletRequest req, HttpServletResponse resp) throws Exception {
        //获取id
        String id = req.getParameter("id");
        System.out.println("===================="+id);

        //调用id查询方法
        Orders orders = ordersService.findById(id);

        //获取所有的信息，然后传入作用域


        //传入作用域
//        req.setAttribute("catalogList",list);
//        req.setAttribute("companyList",list1);
        req.setAttribute("orders",orders);

        //跳转到update.jsp
        req.getRequestDispatcher("/pages/orders-show.jsp").forward(req,resp);
    }

    //模糊查询
    private void query(HttpServletRequest req, HttpServletResponse resp) throws Exception {
        //获取前端传递的当前页码和显示的条数
        String pageNum = req.getParameter("pageNum");
        String pageSize = req.getParameter("pageSize");
        //获取参数
        String name = req.getParameter("name");

        System.out.println(name + "=================================");

        //调用findAll方法，获取orders集合
        List<Orders> list = ordersService.query(name,pageNum,pageSize);

        //将数据交由分页插件处理获取分页信息
        PageInfo<Orders> pageInfo = new PageInfo<Orders>(list);

        //存入作用域
        req.setAttribute("page",pageInfo);

        //页面跳转
        req.getRequestDispatcher("/pages/orders-list.jsp").forward(req,resp);
    }
>>>>>>> 87a0f68c2b3b7de3b37de1968a6eac4ab534cee5
}
